package com.yuedao.sender.controller;

import java.util.ArrayList;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.yuedao.sender.model.BaseInfoCompany;
import com.yuedao.sender.model.BaseInfoCompanyFare;
import com.yuedao.sender.model.BaseInfoCompanyPay;
import com.yuedao.sender.model.BaseInfoCompanyPermit;
import com.yuedao.sender.model.BaseInfoCompanyService;
import com.yuedao.sender.model.BaseInfoCompanyStat;
import com.yuedao.sender.model.BaseInfoDriver;
import com.yuedao.sender.model.BaseInfoDriverApp;
import com.yuedao.sender.model.BaseInfoDriverEducate;
import com.yuedao.sender.model.BaseInfoDriverStat;
import com.yuedao.sender.model.BaseInfoPassenger;
import com.yuedao.sender.model.BaseInfoVehicle;
import com.yuedao.sender.model.BaseInfoVehicleInsurance;
import com.yuedao.sender.model.BaseInfoVehicleTotalMile;
import com.yuedao.sender.service.BaseInfoCompanyFareRepository;
import com.yuedao.sender.service.BaseInfoCompanyPayRepository;
import com.yuedao.sender.service.BaseInfoCompanyPermitRepository;
import com.yuedao.sender.service.BaseInfoCompanyRepository;
import com.yuedao.sender.service.BaseInfoCompanyServiceRepository;
import com.yuedao.sender.service.BaseInfoCompanyStatRepository;
import com.yuedao.sender.service.BaseInfoDriverAppRepository;
import com.yuedao.sender.service.BaseInfoDriverEducateRepository;
import com.yuedao.sender.service.BaseInfoDriverRepository;
import com.yuedao.sender.service.BaseInfoDriverStatRepository;
import com.yuedao.sender.service.BaseInfoPassengerRepository;
import com.yuedao.sender.service.BaseInfoVehicleInsuranceRepository;
import com.yuedao.sender.service.BaseInfoVehicleRepository;
import com.yuedao.sender.service.BaseInfoVehicleTotalMileRepository;
import com.yuedao.sender.service1.BaseinfoService;
import com.yuedao.sender.util.AppLogger;

@RestController
@RequestMapping("/send")
public class DataSenderController {
	
	@Autowired
	BaseInfoCompanyRepository baseInfoCompanyRepository;

	@Autowired
	BaseInfoCompanyStatRepository baseInfoCompanyStatRepository;

	@Autowired
	BaseInfoCompanyPayRepository baseInfoCompanyPayRepository;

	@Autowired
	BaseInfoCompanyServiceRepository baseInfoCompanyServiceRepository;

	@Autowired
	BaseInfoCompanyPermitRepository baseInfoCompanyPermitRepository;

	@Autowired
	BaseInfoCompanyFareRepository baseInfoCompanyFareRepository;

	@Autowired
	BaseInfoDriverRepository baseInfoDriverRepository;

	@Autowired
	BaseInfoDriverAppRepository baseInfoDriverAppRepository;

	@Autowired
	BaseInfoDriverEducateRepository baseInfoDriverEducateRepository;

	@Autowired
	BaseInfoDriverStatRepository baseInfoDriverStatRepository;

	@Autowired
	BaseInfoPassengerRepository baseInfoPassengerRepository;

	@Autowired
	BaseInfoVehicleRepository baseInfoVehicleRepository;

	@Autowired
	BaseInfoVehicleInsuranceRepository baseInfoVehicleInsuranceRepository;

	@Autowired
	BaseInfoVehicleTotalMileRepository baseInfoVehicleTotalMileRepository;
	
	/**
	 * --------------------------------------------------------------------------------------------
	 * @return
	 */
	@Autowired
	BaseinfoService  baseinfos;
	
	protected static AppLogger logger = AppLogger.getInstance();
	
	
	//28张数据表对应接口
	@RequestMapping("/baseInfoCompanyPay")
	public String baseInfoCompanyPay(){
		
		List<BaseInfoCompanyPay> list = new ArrayList<BaseInfoCompanyPay>();
		String message = null;
		try {
			list = baseInfoCompanyPayRepository.findBySendFlag(0);
			
			message=baseinfos.sendBaseInfoCompanyPay(list);
			
			//将发送过的数据标志字段(send_flag)更新为1
			for(int i=0;i < list.size();i++){
				list.get(i).setSendFlag(1);
			}
			
			baseInfoCompanyPayRepository.save(list);
			
		} catch (Exception e) {
			logger.error(e.getMessage());
		}
		return message;
	}
	
	

	@RequestMapping("/baseInfoCompany")
	public String BaseinfoCompany(){
		List<BaseInfoCompany> list = new ArrayList<BaseInfoCompany>();
		String message = null;
		try {
			list = baseInfoCompanyRepository.findBySendFlag(0);
			
			message=baseinfos.sendBaseInfoCompany(list);
			
			//将发送过的数据标志字段(send_flag)更新为1
			for(int i=0;i < list.size();i++){
				list.get(i).setSendFlag(1);
			}
			baseInfoCompanyRepository.save(list);
		} catch (Exception e) {
			logger.error(e.getMessage());
		}
		return message;
	
		
	}
	
	
	
	@RequestMapping("/baseInfoCompanyStat")
	public String baseInfoCompanyStat(){
		List<BaseInfoCompanyStat> list = new ArrayList<BaseInfoCompanyStat>();
		String message = null;
		try {
			list = baseInfoCompanyStatRepository.findBySendFlag(0);
			
			message=baseinfos.sendBaseInfoCompanyStat(list);
			
			//将发送过的数据标志字段(send_flag)更新为1
			for(int i=0;i < list.size();i++){
				list.get(i).setSendFlag(1);
			}
			baseInfoCompanyStatRepository.save(list);
		} catch (Exception e) {
			logger.error(e.getMessage());
		}
		return message;
	}
	
	
	
	@RequestMapping("/baseInfoCompanyService")
	public String baseInfoCompanyService(){
		List<BaseInfoCompanyService> list = new ArrayList<BaseInfoCompanyService>();
		String message = null;
		try {
			list = baseInfoCompanyServiceRepository.findBySendFlag(0);
			
			message=baseinfos.sendBaseInfoCompanyService(list);
			
			//将发送过的数据标志字段(send_flag)更新为1
			for(int i=0;i < list.size();i++){
				list.get(i).setSendFlag(1);
			}
			baseInfoCompanyServiceRepository.save(list);
		} catch (Exception e) {
			logger.error(e.getMessage());
		}
		return message;
		
	}
	
	
	@RequestMapping("/baseInfoCompanyPermit")
	public String baseInfoCompanyPermit(){
		List<BaseInfoCompanyPermit> list = new ArrayList<BaseInfoCompanyPermit>();
		String message = null;
		try {
			list = baseInfoCompanyPermitRepository.findBySendFlag(0);
			
			message=baseinfos.sendBaseInfoCompanyPermit(list);
			
			//将发送过的数据标志字段(send_flag)更新为1
			for(int i=0;i < list.size();i++){
				list.get(i).setSendFlag(1);
			}
			baseInfoCompanyPermitRepository.save(list);
		} catch (Exception e) {
			logger.error(e.getMessage());
		}
		return message;
		
		
	}
	
	
	
	
	@RequestMapping("/baseInfoCompanyFare")
	public String baseInfoCompanyFare(){
		List<BaseInfoCompanyFare> list = new ArrayList<BaseInfoCompanyFare>();
		String message = null;
		try {
			list = baseInfoCompanyFareRepository.findBySendFlag(0);
			
			message=baseinfos.sendBaseInfoCompanyFare(list);
			//将发送过的数据标志字段(send_flag)更新为1
			for(int i=0;i < list.size();i++){
				list.get(i).setSendFlag(1);
			}
			baseInfoCompanyFareRepository.save(list);
		} catch (Exception e) {
			logger.error(e.getMessage());
		}
		return message;
		
	}
	
	
	@RequestMapping("/baseInfoDriver")
	public String baseInfoDriver(){
		List<BaseInfoDriver> list = new ArrayList<BaseInfoDriver>();
		String message = null;
		try {
			list = baseInfoDriverRepository.findAll();
			
			message=baseinfos.sendBaseInfoDriver(list);
			
			//将发送过的数据标志字段(send_flag)更新为1
			for(int i=0;i < list.size();i++){
				list.get(i).setSendFlag(1);
			}
			baseInfoDriverRepository.save(list);
		} catch (Exception e) {
			e.printStackTrace();
			logger.error(e.getMessage());
		}
		return message;
		
	}
	
	
	@RequestMapping("/baseInfoDriverApp")
	public String baseInfoDriverApp(){
		List<BaseInfoDriverApp> list = new ArrayList<BaseInfoDriverApp>();
		String message = null;
		try {
			list = baseInfoDriverAppRepository.findAll();
			
			message=baseinfos.sendBaseInfoDriverApp(list);
			
			//将发送过的数据标志字段(send_flag)更新为1
			for(int i=0;i < list.size();i++){
				list.get(i).setSendFlag(1);
			}
			baseInfoDriverAppRepository.save(list);
		} catch (Exception e) {
			logger.error(e.getMessage());
		}
		return message;
	}
	
	
	@RequestMapping("/baseInfoDriverEducate")
	public String baseInfoDriverEducate(){
		List<BaseInfoDriverEducate> list = new ArrayList<BaseInfoDriverEducate>();
		String message = null;
		try {
			list = baseInfoDriverEducateRepository.findAll();

			message=baseinfos.sendBaseInfoDriverEducate(list);
			
			//将发送过的数据标志字段(send_flag)更新为1
			for(int i=0;i < list.size();i++){
				list.get(i).setSendFlag(1);
			}
			baseInfoDriverEducateRepository.save(list);
		} catch (Exception e) {
			logger.error(e.getMessage());
		}
		return message;
		
	}
	
	
	
	
	@RequestMapping("/baseInfoDriverStat")
	public String baseInfoDriverStat(){
		List<BaseInfoDriverStat> list = new ArrayList<BaseInfoDriverStat>();
		String message = null;
		try {
			list = baseInfoDriverStatRepository.findAll();
			
			message=baseinfos.sendBaseInfoDriverStat(list);
			
			//将发送过的数据标志字段(send_flag)更新为1
			for(int i=0;i < list.size();i++){
				list.get(i).setSendFlag(1);
			}
			baseInfoDriverStatRepository.save(list);
		} catch (Exception e) {
			logger.error(e.getMessage());
		}
		return message;
		
	}	
	
	
	
	
	@RequestMapping("/baseInfoPassenger")
	public String baseInfoPassenger(){
		List<BaseInfoPassenger> list = new ArrayList<BaseInfoPassenger>();
		String message = null;
		try {
			list = baseInfoPassengerRepository.findAll();

			message=baseinfos.sendBaseInfoPassenger(list);
			
			//将发送过的数据标志字段(send_flag)更新为1
			for(int i=0;i < list.size();i++){
				list.get(i).setSendFlag(1);
			}
			baseInfoPassengerRepository.save(list);
		} catch (Exception e) {
			logger.error(e.getMessage());
		}
		return message;
		
	}	
	
	
	
	@RequestMapping("/baseInfoVehicle")
	public String baseInfoVehicle(){
		List<BaseInfoVehicle> list = new ArrayList<BaseInfoVehicle>();
		String message = null;
		try {
			list = baseInfoVehicleRepository.findAll();
			
			message=baseinfos.sendBaseInfoVehicle(list);
			
			//将发送过的数据标志字段(send_flag)更新为1
			for(int i=0;i < list.size();i++){
				list.get(i).setSendFlag(1);
			}
			baseInfoVehicleRepository.save(list);
		} catch (Exception e) {
			logger.error(e.getMessage());
			e.printStackTrace();
		}
		return message;
	}
	
	
	
	/*
	 * baseInfoVehicleInsuranceRepository
	 */
	@RequestMapping("/baseInfoVehicleInsurance")
	public String baseInfoVehicleInsurance(){
		List<BaseInfoVehicleInsurance> list = new ArrayList<BaseInfoVehicleInsurance>();
		String message = null;
		try {
			list = baseInfoVehicleInsuranceRepository.findAll();
			
			message=baseinfos.sendBaseInfoVehicleInsurance(list);
			
			//将发送过的数据标志字段(send_flag)更新为1
			for(int i=0;i < list.size();i++){
				list.get(i).setSendFlag(1);
			}
			baseInfoVehicleInsuranceRepository.save(list);
		} catch (Exception e) {
			logger.error(e.getMessage());
		}
		return message;
		
	}
	
	/**
	 * baseInfoVehicleTotalMileRepository
	 */
	
	@RequestMapping("/baseInfoVehicleTotalMile")
	public String baseInfoVehicleTotalMile(){
		List<BaseInfoVehicleTotalMile> list = new ArrayList<BaseInfoVehicleTotalMile>();
		String message = null;
		try {
			list = baseInfoVehicleTotalMileRepository.findAll();

			message=baseinfos.sendBaseInfoVehicleTotalMile(list);
			
			//将发送过的数据标志字段(send_flag)更新为1
			for(int i=0;i < list.size();i++){
				list.get(i).setSendFlag(1);
			}
			baseInfoVehicleTotalMileRepository.save(list);
		} catch (Exception e) {
			logger.error(e.getMessage());
		}
		return message;
		
	}
	
}
